<template>
  <div class="login_container">
    <!--    登陆区域-->
    <div class="login_box">
      <!--      头像-->
      <div class="avatar_box">
        <img src="../assets/img/qimeng.jpg"/>
      </div>
<!--      表单-->
      <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="100px" class="login_form">
        <el-form-item label="账号" prop="username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" type="password"></el-input>
        </el-form-item>
        <el-form-item style="margin-left: 0px">
          <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
          <el-button @click="resetForm('loginForm')">取消</el-button>
        </el-form-item>
      </el-form>
    </div>

  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username:'',
        password:'',
      },
      loginRules: {
        username: [
          { required: true, message: '请输入账号', trigger: 'blur' },

        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$http.post('/login/doLogin',{username:this.loginForm.username,password:this.loginForm.password}).then(res=>{
            if (res.data.state==200){
              this.$message({
                message: res.data.message,
                type: 'success'
              });
              sessionStorage.setItem("LoginName",res.data.data)
              // localStorage.setItem("LoginName",res.data.data)
              this.$router.push("/main")
            }else {
              this.$message.error(res.data.message);
            }
            console.log("res",res)

          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }

}
</script>

<style lang="less" scoped>
.login_container{
  height: 100%;
  background-color: aquamarine;
}
.login_box{
  width: 450px;
  height: 380px;
  background: #f0f2f5 url(~@/assets/background.svg) no-repeat 50%;
  background-size: 100%;


  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  .avatar_box{
    width: 130px;
    height: 130px;
    border: 1px solid #eeeeee;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
    margin: -65px auto;
    background-color: #FFFFFF;
  }
  img{
    width: 100%;
    height: 100%;
    border-radius: 50%;
  }
  .login_form{
    position: absolute;
    width: 100%;
    box-sizing: border-box;
    padding: 0px 20px;
    bottom: 0px;
  }
}

</style>
